import React, { useEffect, useState } from 'react'
import Comp1 from '@/components/Comp1'
import Comp2 from '@/components/Comp2'
import { Button, Space, message } from 'antd';
import { PlayCircleOutlined } from '@ant-design/icons'
import { useRoutes, Link, useLocation, useNavigate } from 'react-router-dom'
import routes from './router';

function Tologin() {
  const navgiateto = useNavigate()
  useEffect(() => {
    navgiateto('/login')
    message.error('请登录', 2)
  })
  return <div></div>
}
function Topage1() {
  const navgiateto = useNavigate()
  useEffect(() => {
    navgiateto('/page1')
    message.success('已经登录', 2)
  })
  return <div></div>
}

function Beforerouterenter() {
  const outlet = useRoutes(routes)
  const location = useLocation()
  let token = localStorage.getItem('token')
  if (location.pathname == '/login' && token) {
    return <Topage1 />
  }
  if (location.pathname !== '/login' && !token) {
    return <Tologin />

  }
  return outlet
}
function App() {
  const [count, setCount] = useState(0)

  return (
    <div className="App">
      <Beforerouterenter />
    </div>
  )
}

export default App
